package model;

import java.util.List;
import java.util.Random;

/**
 * Represents a grass object in the simulation field.
 * 
 * @author Leo van Alphen
 * @version 2014.01.26
 */

public class ModifierGrass extends FieldModifier {

	// The number of steps it takes for grass to regrow
    private static int REGROWTH_RATE = 2;
    // The age of the grass, when the grass is eaten age is reset to zero
    private int age;
    // A shared random number generator to control initial grass age.
    private static final Random rand = Randomizer.getRandom();	
	
    /**
     * Grass constructor. Pass a boolean true to set a random age of the grass.
     * @param boolean randomAge
     * @param Field the simulation field
     * @param Location the location of the grass on the field
     */ 
	public ModifierGrass(boolean randomAge, Field field, Location location) {
		super(field, location);	
        if(randomAge) {
            age = rand.nextInt();
        }
        else {
            age = 0;
        }
	}

	/**
     * Perform the actor’s regular behavior.
     * @param newActors A list for receiving newly created actors.
     */
	public void act(List<Actor> newActors) {
		incrementAge();
	}
	/**
     * Increase the age of the actor by one.
     * @return void
     */	
	protected void incrementAge() {
		age++;
	}
	/**
     * Checks whether the grass had regrown enough to be edible again
     * @return boolean true if edible
     */	
	protected boolean isEdible() {
		if(age >= REGROWTH_RATE) {
			return true;
		} else {
			return false;
		}
	}
	/**
     * Sets the age of the grass
     * @param int age
     */	
	protected void setAge(int age) {
		this.age = age;
	}
	/**
     * Sets the number of steps it takes for grass to regrow after being eaten
     * @return void
     * @param int regrowth rate of grass
     */	
	public static void setRegrowthRate(int REGROWTH_RATE) {
		ModifierGrass.REGROWTH_RATE = REGROWTH_RATE;
	}
	/**
     * Returns the number of steps it takes for grass to regrow after being eaten
     * @return int regrowth rate of grass
     */	
	public static int getRegrowthRate() {
		return REGROWTH_RATE;
	}
	
	public String toString() {
		return "Grass";
	}
	
}
